
class Node:
    def __init__(self,val):
        self.val = val
        self.next = None

def LinkedList(nums):
    for count,value in enumerate(nums):
        if count ==0:
            head=Node(value)
            cur = head
        else:
            cur.next =Node(value)
            cur = cur.next
    return head

def travel(head):
    list =[]
    while head:
        list.append(head.val)
        head = head.next
    return list

def reverse_linked_list(head):
    cur = head
    prev = None
    while cur:
        cur.next,prev,cur = prev,cur,cur.next

    return prev

if __name__=="__main__":
    a = LinkedList([99, 1, 34, 2, 6, 1, 35, 657, 5, 3, 8, 7])
    c =reverse_linked_list(a)
    print(travel(c))